package src.jdbc1;

import java.sql.*;

public class jdbcStudy {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //连接数据库
        Connection root = DriverManager.getConnection("jdbc:mysql://localhost:3306/stu?useSSL=false&serverTimezone=UTC", "root", "");
        //定义查询语句
        String sql= "select * from tbl_lixue";
        //获取查询对象
        Statement statement = root.createStatement();
        //执行sql语句
        ResultSet resultSet = statement.executeQuery(sql);
        //解析数据
        while(resultSet.next()){
            int id = resultSet.getInt("id");
            String username = resultSet.getString("username");
            String password = resultSet.getString("password");
            System.out.println(id+"|"+username+"|"+password);
        }
        //释放资源
        resultSet.close();
        root.close();;
    }
}
